//
//  HNSH_GoodsDetailBottomView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/25.
//

#import "HNSH_GoodsDetailBottomView.h"

@interface HNSH_GoodsDetailBottomView ()

/* moneyDesLabel */
@property (nonatomic, strong) UILabel *moneyDesLabel;
/* moneyLabel */
@property (nonatomic, strong) UILabel *moneyLabel;
/* addCartButton */
@property (nonatomic, strong) UIButton *addCartButton;
/* buyButton */
@property (nonatomic, strong) UIButton *buyButton;
/* lineView */
@property (nonatomic, strong) UIView *lineView;

@end

@implementation HNSH_GoodsDetailBottomView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
        [self configUI];
    }
    return self;
}

- (void)setMoneyString:(NSString *)moneyString {
    _moneyString = moneyString;
    self.moneyLabel.text = moneyString;
}

- (void)configUI {
    [self addSubview:self.lineView];
    [self addSubview:self.moneyDesLabel];
    [self addSubview:self.moneyLabel];
    [self addSubview:self.addCartButton];
    [self addSubview:self.buyButton];
    
    [self.moneyDesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(7);
        make.height.mas_equalTo(16);
    }];
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(23);
        make.height.mas_equalTo(20);
    }];
}

#pragma mark lazy
- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 54, kScreenWidth, 1)];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#EDEDED"];
    }
    return _lineView;
}

- (UILabel *)moneyDesLabel{
    if (!_moneyDesLabel) {
        _moneyDesLabel = [UILabel new];
        _moneyDesLabel.text = @"可得购物值：";
        _moneyDesLabel.textColor = [UIColor appGrayLabelColor];
        _moneyDesLabel.font = [UIFont systemFontOfSize:12];
    }
    return _moneyDesLabel;
}

- (UILabel *)moneyLabel{
    if (!_moneyLabel) {
        _moneyLabel = [UILabel new];
        _moneyLabel.text = @"199.00";
        _moneyLabel.textColor = [UIColor appBlackLabelColor];
        _moneyLabel.font = [UIFont boldSystemFontOfSize:16];
    }
    return _moneyLabel;
}

- (UIButton *)addCartButton {
    if (!_addCartButton) {
        _addCartButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _addCartButton.frame = CGRectMake(kScreenWidth-134-102, 7, 102, 40);
        [_addCartButton setTitle:@"加入购物车" forState:UIControlStateNormal];
        [_addCartButton setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        _addCartButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        _addCartButton.backgroundColor = [UIColor colorWithHexString:@"#FB6F1C"];
        _addCartButton.layer.cornerRadius = 20.0f;
        _addCartButton.layer.masksToBounds = YES;
        WeakSelf(weakSelf);
        [[_addCartButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (weakSelf.addCartBlock) {
                weakSelf.addCartBlock();
            }
        }];
    }
    return _addCartButton;
}

- (UIButton *)buyButton {
    if (!_buyButton) {
        _buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _buyButton.frame = CGRectMake(kScreenWidth-118, 7, 102, 40);
        [_buyButton setTitle:@"立即购买" forState:UIControlStateNormal];
        [_buyButton setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        _buyButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        _buyButton.backgroundColor = [UIColor appGreenColor];
        _buyButton.layer.cornerRadius = 20.0f;
        _buyButton.layer.masksToBounds = YES;
        WeakSelf(weakSelf);
        [[_buyButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (weakSelf.buyBlock) {
                weakSelf.buyBlock();
            }
        }];
    }
    return _buyButton;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
